Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

falafel

Package Overview
Dependencies
Maintainers
6
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

falafel

transform the ast on a recursive walk

  • 2.2.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
602K
decreased by-8.07%
Maintainers
6
Weekly downloads
 
Created

What is falafel?

The 'falafel' npm package is a tool for parsing and transforming JavaScript code. It allows you to traverse and manipulate the abstract syntax tree (AST) of JavaScript code, making it useful for tasks such as code analysis, transformation, and instrumentation.

What are falafel's main functionalities?

Parsing JavaScript Code

This feature allows you to parse JavaScript code into an AST and traverse it. In this example, the code parses a simple JavaScript snippet and logs the type of each node in the AST.

const falafel = require('falafel');
const src = 'let x = 5;';
falafel(src, function (node) {
  console.log(node.type);
});

Transforming JavaScript Code

This feature allows you to transform JavaScript code by modifying the AST. In this example, the code changes the variable declaration from 'x' to 'y' and updates its value.

const falafel = require('falafel');
const src = 'let x = 5;';
const output = falafel(src, function (node) {
  if (node.type === 'VariableDeclarator' && node.id.name === 'x') {
    node.update('y = 10');
  }
});
console.log(output.toString());

Code Instrumentation

This feature allows you to instrument JavaScript code by injecting additional code into the AST. In this example, the code adds a console log before each return statement.

const falafel = require('falafel');
const src = 'function add(a, b) { return a + b; }';
const output = falafel(src, function (node) {
  if (node.type === 'ReturnStatement') {
    node.update('console.log("Returning: ", ' + node.argument.source() + '); ' + node.source());
  }
});
console.log(output.toString());

Other packages similar to falafel

Keywords

FAQs

Package last updated on 11 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc